package net.ru.topdog.lunchy.dao;

import java.io.FileReader;
import java.util.List;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;

public class XMLDAOFactory extends DAOFactory {
	private String disdOutput;
	private String typeOutput;

	public XMLDAOFactory(String configFile) {

		try {
			SAXBuilder parser = new SAXBuilder();
			FileReader fr = new FileReader(configFile);
			Document rDoc = parser.build(fr);
			List<Element> temp = rDoc.getRootElement().getChildren();

			disdOutput = temp.get(0).getAttributeValue("disdOutput", "");
			typeOutput = temp.get(0).getAttributeValue("typeOutput", "");

		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}

	@Override
	public DishDAO getDishDAO() {
		return new XMLDishDAO(disdOutput);
	}

	@Override
	public TypeDAO getTypeDAO() {
		// TODO Auto-generated method stub
		return new XMLTypeDAO(typeOutput);
	}

}
